package beavers.studio.golfberry.screens;

import beavers.studio.golfberry.FileManager;
import beavers.studio.utilities.threads.MapDownloadThread;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.component.BitmapField;

public class MapScreen extends GolfScreen {
	//Static attribute
	public static boolean m_Run = false;

	//Screen attributes
	private int m_MaxImages;
	private int m_NumImages;
	
	//Constructor
	public MapScreen() {
		//Super
		super(GolfScreen.ID.MAP);
    	
		//Initialize maximum images number
		m_MaxImages = 3;
		
		//Load and display existing image 
		int i = 0;
		byte[] m_Image;
		while ((m_Image = FileManager.inst().loadImage("map-" + i + ".jpeg"))!=null&&(i<m_MaxImages)) {
			add(new BitmapField(Bitmap.createBitmapFromBytes(m_Image, 0, m_Image.length, 1)));
			i++;
		}
		
		//Init current number of images
		m_NumImages = i;
		
		//Download if hasn't
		if (!m_Run) {
			MapDownloadThread m_Thread = new MapDownloadThread(this);
			m_Thread.start();
		}
	}
	
	//Getter-Setter
	public int getMaximumImages() 		{ 	return m_MaxImages;		}
	public int getNumImages()			{ 	return m_NumImages; 	}
	public void setNumImages(int num)	{ 	m_NumImages = num;		}
}
